//## 작업지시 서브 메뉴
function fnOrderShow(t)
{
	if (t == "0")
	{
		$("#orderSubMenu").find("tr").find("td").eq(0).css("font-weight","bold");
		$("#orderSubMenu").find("tr").find("td").eq(1).css("font-weight","normal");
		$("#orderSubMenu").find("tr").find("td").eq(2).css("font-weight","normal");
		$("#layer01").css("display","");		
		$("#layer02").css("display","none");
		$("#layer03").css("display","none");
	}
	if (t == "1")
	{
		$("#layer01").css("display","none");		
		$("#layer02").css("display","");	
		$("#layer03").css("display","none");
		$("#orderSubMenu").find("tr").find("td").eq(0).css("font-weight","normal");
		$("#orderSubMenu").find("tr").find("td").eq(1).css("font-weight","bold");
		$("#orderSubMenu").find("tr").find("td").eq(2).css("font-weight","normal");
	}
	if (t == "2")
	{
		$("#layer01").css("display","none");		
		$("#layer02").css("display","none");	
		$("#layer03").css("display","");
		$("#orderSubMenu").find("tr").find("td").eq(0).css("font-weight","normal");
		$("#orderSubMenu").find("tr").find("td").eq(1).css("font-weight","normal");
		$("#orderSubMenu").find("tr").find("td").eq(2).css("font-weight","bold");
	}
}

//## 오더 품목 콤보 Refresh ####################
function fnSetCompOrderArticle(seq)
{
	var valUrl = "/action/common/listCompOrder.asp";
	var param = "seq="+seq
	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			fnSessionCheck($(xml).find("MSG").text());
			$("#compOrderArticleSeq").html("<option value=\"0\">-오더품목-</option>");

			$(xml).find("ArticleList").each(function(idx){
				$("#compOrderArticleSeq").append("<option value=\""+$(this).find("seq").text()+"\""+$(this).find("chk").text()+">"+$(this).find("compPrdCd").text()+"/"+$(this).find("compPrdNm").text()+"/"+$(this).find("amount").text()+"ea</option>");
			});
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

//## 원자재 소요 정보 저장 ##################
function fnSaveOutSrc()
{
	if (!$("#fullLotNo").val())
	{
		alert("LotNo가 생성 후에 적용이 가능합니다");
		return;
	}
	if (!$("#orgSrcCd").val())
	{
		alert("원자재를 선택해 주세요");
		$("#orgSrcCd").focus();
		return;
	}
	if (!$("#orgSrcCnt").val())
	{
		alert("원자재 소모량을 바르게 넣어주세요");
		$("#orgSrcCnt").focus();
		return;
	}
	var lotNo = $("#fullLotNo").val()+"-"+$("#lotSubNo").val();
	var valUrl  = '/action/srcStore/save.asp';
	var param  = "srcCd="+$("#orgSrcCd").val();
		param += "&input=0";
		param += "&output="+$("#orgSrcCnt").val();
		param += "&issuedMemo="+lotNo;
		param += "&flag=Y";
	
	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			fnSessionCheck($(xml).find("MSG").text());
			if ($(xml).find("MSG").text() == "Save OK!")
			{
				alert("Source Save OK!");
				$("#orgSrcQty").html($(xml).find("VAL").text());
			}
			else alert($(xml).find("MSG").text());
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});

}

//## 작업지시 정보 저장 ####################
function fnSave()
{
	if (!$("#compCd").val())
	{
		alert("거래처를 선택해 주세요!");
		$("#compCd").focus();
		return;
	}
	if (!$("#prdCd").val())
	{
		alert("제품명을 바르게 선택해 주세요!");
		$("#prdCd").focus();
		return;
	}
	if (!$("#qty").val())
	{
		alert("수량을 바르게 입력해 주세요!");
		$("#qty").focus();
		return;
	}
	if (!$("#procTypeCd").val())
	{
		alert("공정그룹을 바르게 입력해 주세요!");
		$("#procTypeCd").focus();
		return;
	}
//	if (!$("#orgSrcCnt").val() && $("#orgSrcCd").val())
//	{
//		alert("원자재 소모량을 바르게 입력해 주세요!");
//		$("#orgSrcCnt").focus();
//		return;
//	}

	var param  = "compCd="+$("#compCd").val();
		param += "&prdCd="+encodeURIComponent($("#prdCd").val());
		param += "&qty="+encodeURIComponent($("#qty").val());
		param += "&sourceLotNo="+encodeURIComponent($("#sourceLotNo").val());
		param += "&sourceSize="+encodeURIComponent($("#sourceSize").val());
		param += "&deliveryDt="+encodeURIComponent($("#deliveryDt").val());
		param += "&amount="+encodeURIComponent($("#amount").val());
		param += "&compMemo="+encodeURIComponent($("#compMemo").val());
		param += "&workMemo="+encodeURIComponent($("#workMemo").val());
		param += "&remarks="+encodeURIComponent($("#remarks").val());
		param += "&fullLotNo="+$("#fullLotNo").val();
		param += "&lotSubNo="+$("#lotSubNo").val();
		param += "&planDt="+$("#planDt").val();
		param += "&procTypeCd="+$("#procTypeCd").val();
		param += "&orgSrcCnt="+$("#orgSrcCnt").val();
		param += "&orgSrcCd="+$("#orgSrcCd").val();
		param += "&flag="+$("#flag").val();
		param += "&type="+$("#type").val();
		param += "&compOrderArticleSeq="+$("#compOrderArticleSeq").val();
		param += "&updateDt="+encodeURIComponent($("#updateDt").val());

	$.ajax({
		url: '/action/jobOrder/save.asp',
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			if ($(xml).find("MSG").text() == "Save OK!")
			{
				fnReset();
				alert("Save OK!!");
				fnOrderShow('0');
				grid01List();
			}
			else alert($(xml).find("MSG").text());
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

//## 작업지시 정보 그리드 표시 ####################

var G_curPage01 = 1;

function grid01List(page)
{	
	var gridNo = 1;
	var xmlNode = "OrderList";

	fnResetGrid(gridNo);
	fnNewLoading(gridNo);

	if (!page) page = G_curPage01;
	if (page == undefined) page = 1;
	else G_curPage01 = page;
	var limit = 50;

	var valUrl = "/action/jobOrder/list.asp";
	var Parm = "findCompNm="+encodeURIComponent($("#findCompNm").val());
		Parm += "&findPrdNm="+encodeURIComponent($("#findPrdNm").val());
		Parm += "&findLotNo="+encodeURIComponent($("#findLotNo").val());
		Parm += "&findLotYear="+$("#findLotYear").val();
		Parm += "&findType="+$("#findType").val();
		Parm += "&findGoods="+$("#findGoods").val();
	if (xMode=="Debug") window.open(valUrl+'?xMode=debug&'+Parm);

	// 그리드 헤더를 기준으로 Cell의 폭을 구해온다.
	var cellWidth = fnGetGridCellWidth(gridNo);	
	// Cell의 정렬방식
	var cellAlign = ",,left,,,,,,,,,,".split(",");
	// Cell의 링크 걸지 여부 결정
	var cellLink = ",,,,,,,,,,N,N".split(",");

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: Parm,
		success: function(xml){
			var gridList = "";
			var k = 1;
			var ttlCnt = $(xml).find(xmlNode).length;
			var startNo = (parseInt(page,10)-1) * limit;
			var endNo = parseInt(page,10) * limit;
			var bgColor = "#FFF";
			var chkCnt = 0;
			
			// 그리드의 부가 정보(레코드수, 페이징) 표시 또는 가리기
			fnGridExtraInfo(gridNo, ttlCnt, page, limit); 

			if (ttlCnt <= endNo) endNo = ttlCnt;
			var no = endNo;
			var empty = "&nbsp;";
			var showFlag = "";
			var ttlRestCnt = 0;
			$(xml).find(xmlNode).each(function(idx){

				if (k>startNo && k<=endNo)
				{
					var fullLotNo			= $(this).find("fullLotNo").text();
					var lotSubNo			= $(this).find("lotSubNo").text();
					var company			= $(this).find("company").text();
					var prdNm				= $(this).find("prdNm").text();
					var qty						= $(this).find("qty").text();	
					var deliveryDt			= $(this).find("deliveryDt").text();	
					var procTypeNm		= $(this).find("procTypeNm").text();	
					//var sourceLotNo		= $(this).find("sourceLotNo").text();	
					var etc						= $(this).find("etc").text();	
					var type					= $(this).find("type").text();	
					var amount				= $(this).find("amount").text();	
					var curProcess		= $(this).find("curProcess").text();
					var flag					= $(this).find("flag").text();
					var goodsQty			= $(this).find("goodsQty").text();
					var badRate			= $(this).find("badRate").text();
					var ingQty				= $(this).find("ingQty").text();

					if(flag == "Y") showFlag = "유효";
					else if(flag == "B") showFlag = "LOT불량";
					else if(flag == "E") showFlag = "완료";
					else if(flag == "H") showFlag = "보류";
					else showFlag = "무효";

					bgColor="#FFF";
					if (flag == "N") { bgColor = "#F2F2F2"; tagFirst = "<font color=\"#CCCCCC\">"; tagLast = "</font>"; }
					else if (flag == "E") { bgColor = "#fff0ec"; }
					else if (flag == "B") { bgColor = "#d8ddcc"; }
					else 
					{
						if (!bgColor) bgColor = "#FFFFFF";
					}
					
					var bold = "";
					if (goodsQty.split(",").join("") > 0)
					{
						bold = "font-weight:bold;";
					}
							
					var showLotNo = fullLotNo + "-" + lotSubNo;
					showLotNo = showLotNo.replace("-0","");
					if(!deliveryDt) deliveryDt = "&nbsp;";
					
					var style = "color:cc0099;";
					if (badRate == "&nbsp;") style="";
					
					var gCnt = goodsQty.split(",").join("");
					
					if (flag != "N") ttlRestCnt = parseInt(ttlRestCnt,10)+ parseInt(gCnt,10);
					var jLink = "<a href=\"javascript:fnOpenLot('"+fullLotNo+"-"+lotSubNo+"')\">[가공]</a>";
				
					var arrVal = new Array();
					arrVal[0] = "<p style='"+bold+"'>"+showLotNo+"</p>";
					arrVal[1] = "<p style='"+style+"'>"+company+"</p>";
					arrVal[2] = "<p style='"+style+"'>"+prdNm+"</p>";
					arrVal[3] = "<p style='"+style+"'>"+qty+"</p>";
					arrVal[4] = "<p style='"+style+"'>"+badRate+"</p>";
					arrVal[5] = "<p style='"+style+"'>"+procTypeNm+"&nbsp;"+"</p>";
					arrVal[6] = "<p style='"+style+"'>"+etc+"&nbsp;"+"</p>";
					arrVal[7] = "<p style='"+style+"'>"+goodsQty+"</p>";
					arrVal[8] = "<p style='"+style+"'>"+ingQty+"</p>";
					arrVal[9] = "<p>"+showFlag+"</p>";
					arrVal[10] = "<p style='"+style+"'>"+jLink+"</p>";
					arrVal[11] = "<p><a href=\"javascript:fnJobOrderPrint('"+fullLotNo+"','"+lotSubNo+"')\">[출력]</a>&nbsp;<a href=\"javascript:fnAddJobOrder('"+fullLotNo+"','"+lotSubNo+"')\">[작업연장]</a></p>";
										
					var link = "fnSetJobOrder('"+fullLotNo+"','"+lotSubNo+"')";

					//gridList = fnDrawCell(lotYear, lotNo, lotSubNo, processCd);
					gridList = fnDrawCell(arrVal, bgColor, cellWidth, cellAlign, '', link, cellLink);

					$("#"+"gridBody"+gridNo).append(gridList);
				}
				no = parseInt(endNo,10)-parseInt(k,10);
				k++;			
			});
			
			if ($("#findPrdNm").val())
			{
				cellAlign = ",,,,,,,,,,,,".split(",");
				var arrVal = new Array();
				arrVal[0] = "<p>"+empty+"</p>";
				arrVal[1] = "<p>"+empty+"</p>";
				arrVal[2] = "<p style='font-weight:bold;'>TOTAL</p>";
				arrVal[3] = "<p>"+empty+"</p>";
				arrVal[4] = "<p>"+empty+"</p>";
				arrVal[5] = "<p>"+empty+"</p>";
				arrVal[6] = "<p>"+empty+"</p>";
				arrVal[7] = "<p style='font-weight:bold;'>"+getNumWithComma(ttlRestCnt)+"</p>";
				arrVal[8] = "<p>"+empty+"</p>";
				arrVal[9] = "<p>"+empty+"</p>";
				arrVal[10] = "<p>"+empty+"</p>";
				arrVal[11] = "<p>"+empty+"</p>";
				var link = "";
				bgColor="#FFF";
				gridList = fnDrawCell(arrVal, bgColor, cellWidth, cellAlign, '', link, cellLink);

				$("#"+"gridBody"+gridNo).prepend(gridList);
				$("#"+"gridBody"+gridNo).append(gridList);
			}
		},
		error: function(xml){
			alert('Error!!\r\n'+xml.responseText);
		}
	});
}

//## 가공 공정 상세 열기
function fnOpenLot(lotNo)
{
	if (!lotNo) lotNo = $("#fullLotNo").val() + "-" +$("#lotSubNo").val();
	var curl = "/pop_jobOrder.asp?lotNo="+lotNo
	window.open(curl, 'LOT_DETAIL', 'width=1010px,height=780px');
}

//## 동일 작업 연장 하기 ####################
function fnAddJobOrder(fullLotNo, lotSubNo)
{
	//fnReset();
	fnSetJobOrder(fullLotNo, lotSubNo);
	$("#lotSubNo").val("A");
}

//## 작업지시 상세정보 표시 ####################
function fnSetJobOrder(fullLotNo, lotSubNo)
{
	var valUrl = "/action/jobOrder/view.asp";
	var param = "fullLotNo="+fullLotNo;
		param += "&lotSubNo="+lotSubNo;

	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);
	fnReset();

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			fnOrderShow('1');

			$("#fullLotNo").val($(xml).find("fullLotNo").text());
			if ($("#lotSubNo").val() != "A")
			{
				$("#lotSubNo").val($(xml).find("lotSubNo").text());
				$("#curProcess").val($(xml).find("curProcess").text());
			}
			fnSetCompOrderArticle($(xml).find("compOrderArticleSeq").text());
			$("#prdCd").val($(xml).find("prdCd").text());
			$("#qty").val($(xml).find("qty").text());
			$("#restQty").val($(xml).find("restQty").text());
			$("#deliveryDt").val($(xml).find("deliveryDt").text());
			$("#procTypeCd").val($(xml).find("procTypeCd").text());
			$("#sourceLotNo").val($(xml).find("sourceLotNo").text());
			$("#sourceSize").val($(xml).find("sourceSize").text());
			$("#amount").val($(xml).find("amount").text());
			$("#compMemo").val($(xml).find("compMemo").text());
			$("#workMemo").val($(xml).find("workMemo").text());
			$("#remarks").val($(xml).find("remarks").text());
			$("#planDt").val($(xml).find("planDt").text());
			$("#orgSrcCd").val($(xml).find("orgSrcCd").text());
			$("#orgSrcCnt").val("1");			
			$("#orgSrcQty").html($(xml).find("orgSrcCnt").text());
			$("#compOrderArticleSeq").val($(xml).find("compOrderArticleSeq").text());
			$("#flag").val($(xml).find("flag").text());
			$("#updateDt").val($(xml).find("updateDt").text());
			$("#type").val($(xml).find("type").text());
			$("#badRate").html($(xml).find("badRate").text()+" %");
			$("#ingQty").html($(xml).find("ingQty").text());
			fnFindCompany($(xml).find("company").text(),$(xml).find("compCd").text(),'compCd');
			setTimeout("fnShowProcSetDetail('"+$(xml).find("procTypeCd").text()+"','"+fullLotNo+"','"+lotSubNo+"');",1000);

		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

//## 작업지시 정보 Reset 기능
function fnReset()
{
	$("#fullLotNo").val("");
	$("#lotSubNo").val("");
	$("#compCd").val("");
	$("#compNm").val("");
	$("#prdCd").val("");
	$("#qty").val("");
	$("#restQty").val("");
	$("#deliveryDt").val("");
	$("#procTypeCd").val("");
	$("#sourceLotNo").val("");
	$("#sourceSize").val("");
	$("#amount").val("");
	$("#compMemo").val("");
	$("#workMemo").val("");
	$("#remarks").val("");
	$("#planDt").val("");
	$("#curProcess").val("");
	$("#orgSrcCd").val("");
	$("#orgSrcQty").html("0");
	$("#orgSrcCnt").val("");
	$("#flag").val("Y");
	$("#type").val("D");
	fnShowUnitReset();
	$("#processCds").val("");
	$("#procTypes").val("");
	$("#badRate").html("");
	$("#updateDt").html("");
	$("#ingQty").html("");
	$("#showProcSetDetail").html("&nbsp; &nbsp; &nbsp; Loading....");
	$("#showProcSetDetail").css("display","none");

	fnOrderShow('1');
	fnSetCompOrderArticle("");
}


//## 검색 Reset 기능
function fnSearchReset()
{
	$("#findProcess").val("");
}

//## 공정그룹 상세 정보
function fnShowProcSetDetail(procTypeCd,fullLotNo,lotSubNo)
{
	if (!procTypeCd)
	{
		$("#showProcSetDetail").html("&nbsp; &nbsp; &nbsp; Loading....");
		$("#showProcSetDetail").css("display","none");
		fnShowUnitReset();
	}
	else
	{
		var valUrl = "/action/jobOrder/viewProcSetDetail.asp";
		var param = "procTypeCd="+procTypeCd;
			param += "&fullLotNo="+fullLotNo;

		$("#showProcSetDetail").css("display","");
		if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

		$.ajax({
			url: valUrl,
			type: 'POST',
			dataType: 'xml',
			data: param,
			success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());
				
				$("#showProcSetDetail").html("&nbsp; "+$(xml).find("procSet").text());
				fnDrawProcess($(xml).find("processCds").text(),fullLotNo,lotSubNo);
				$("#procTypes").val($(xml).find("procTypes").text());
				var procCds = $(xml).find("processCds").text();
				var allProcCds = $(xml).find("allProcCds").text();
				$("#processCds").val(procCds);
				var divProcCd = allProcCds.split(",");
				for (k=0; k<divProcCd.length; k++)
				{
					var j = k+1;
					$("#"+"processCds"+j).val(divProcCd[k].split("/").join(","));
				}

			},
			error: function(xml){
				alert('Error!!');
				alert(xml.responseText);
			}
		});
	}
}

//## 공정 Table 그리기
function fnDrawProcess(processCds,fullLotNo,lotSubNo)
{
	var divProcCds = processCds.split(",");
	fnShowUnitReset(); // 공정 Layer Reset
	
	for (k=0; k<divProcCds.length; k++)
	{
		if (divProcCds[k])
		{
			setTimeout("fnShowUnitProcess('"+divProcCds[k]+"','"+k+"','"+fullLotNo+"','"+lotSubNo+"');",1000);
		}
	}
	if (fullLotNo) setTimeout("fnSetOrderMemo('"+fullLotNo+"','"+lotSubNo+"')",1000);
}

//## 검사 측정 팝업 열기
function fnCheckingResult(rank, type)
{
	var x = new Date();
	var nTime = x.getTime();
	var fullLotNo = $("#fullLotNo").val();
	var subLotNo = $("#lotSubNo").val();
	window.open("checking.asp?fullLotNo="+fullLotNo+"&lotSubNo="+subLotNo+"&rank="+rank+"&type="+type, "Checking_"+nTime, "width=1365,height=500,scrollbars=yes");
}

//## 공정 메모 열기
function fnAddMemo(id)
{
	var x = new Date();
	var nTime = x.getTime();
	var fullLotNo = $("#fullLotNo").val();
	var subLotNo = $("#lotSubNo").val();
	$("#"+"processRank").val(id);

	var param  = "fullLotNo="+$("#fullLotNo").val();
		param += "&lotSubNo="+$("#lotSubNo").val();
		param += "&processRank="+id;

	$.ajax({
		url: '/action/jobOrder/viewMemo.asp',
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());
	
			var orderMemo = $(xml).find("orderMemo").text();
			$("#orderMemo").val(orderMemo);

		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});

	//var Y = event.pageY  + $(window).scrollTop();			
	//var X = event.pageX + $(window).scrollLeft();
//	$("#jobOrderMemo").css("top",Y);
//	$("#jobOrderMemo").css("left",X);
//	var $layerPopupObj = $('#jobOrderMemo');
//	var left = ( $(window).scrollLeft() + ($(window).width() - $layerPopupObj.width()) / 2 );
//	var top = ( $(window).scrollTop() + ($(window).height() - $layerPopupObj.height()) / 2 );
//	alert(top+"/"+$(window).scrollLeft())

	$("#jobOrderMemo").css("top",400);
	$("#jobOrderMemo").css("left",400);
	$("#jobOrderMemo").css("display","");
	$("#orderMemo").focus();
}

//## 공정 메모 저장
function fnSaveMemo()
{
	var param  = "orderMemo="+encodeURIComponent($("#orderMemo").val());
		param += "&fullLotNo="+$("#fullLotNo").val();
		param += "&lotSubNo="+$("#lotSubNo").val();
		param += "&processRank="+$("#processRank").val();

	$.ajax({
		url: '/action/jobOrder/saveMemo.asp',
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			var msg = $(xml).find("MSG").text();
			var divMsg = msg.split("^##^");

			if (divMsg[0] == "Save OK!")
			{
				alert("Save OK!!");
				fnMemoClose();
				var memo = divMsg[1];
				if(divMsg[1]) 
				{
					$("#"+$("#processRank").val()).css("display","");
					memo = "☞ " +memo;
				}
				else
				{
					$("#"+$("#processRank").val()).css("display","none");
				}
				$("#"+$("#processRank").val()).html(memo);

				$("#orderMemo").val("");
				$("#processRank").val("");
			}
			else alert($(xml).find("MSG").text());
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

function fnMemoClose()
{
	$("#jobOrderMemo").css("display","none");
}

//## 메모정보 표시 ####################
function fnSetOrderMemo(fullLotNo,lotSubNo)
{
	var valUrl = "/action/jobOrder/listMemo.asp";
	var param = "fullLotNo="+fullLotNo;
		param += "&lotSubNo="+lotSubNo;

	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			$(xml).find("Memos").find("MemoList").each(function(rank)
			{
				var memoId = $(this).find("processRank").text();
				var memo = $(this).find("orderMemo").text();

				if (memo) 
				{
					$("#"+memoId).css("display","");
					memo = "☞ " +memo;
				}
				$("#"+memoId).html(memo);
			});

		},
		error: function(xml){
			//alert('Error!!');
			alert(xml.responseText);
		}
	});
}



//## 단위 공정 Table 그리기
function fnShowUnitProcess(processCd,posit,fullLotNo,lotSubNo)
{
	
	var valUrl = "/action/jobOrder/viewProcDetail.asp";
	var param = "processCd="+processCd;
		param += "&posit="+posit;
		param += "&fullLotNo="+fullLotNo;
		param += "&lotSubNo="+lotSubNo;

	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);
	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			$(xml).find("ProcDetailInfo").find("ProcDetail").each(function(rank)
			{
				var P_cd = $(this).find("processCd").text();
				var P_nm = $(this).find("processNm").text();
				var P_wk = $(this).find("working").text();
				var P_ex = $(this).find("execTime").text();
				var P_wkDt = $(this).find("workDt").text();
				var P_uid = $(this).find("userId").text();
				var P_goodQty = $(this).find("goodQty").text();
				var P_badQty = $(this).find("badQty").text();
				var P_etc = $(this).find("etc").text();
				var P_tp = $(this).find("type").text();
				var posit = $(this).find("posit").text();
				var P_rank = $(this).find("rank").text();
				var vRank = "";
				if (posit == "1") vRank = P_rank - 99;

				var unitProcHeader = "";				
				//unitProcHeader += "<span style=\"font-size:12pt;position:absolute;width:120px\">^processNm</span><input type=\"text\" style=\"width:130px;text-align:right;font-weight:bold;color:#333;border:0px;padding-right:5px;\" value=\""+vRank+"\" readOnly>";
				unitProcHeader += "<span style=\"font-size:12pt;position:absolute;width:120px\">^processNm</span><input type=\"text\" style=\"width:130px;text-align:right;font-weight:bold;color:#333;border:0px;padding-right:5px;\" readOnly> ";
				unitProcHeader += "<img src=\"http://www.noahtech.kr/img/icon_select.png\" style=\"cursor:hand\" onClick=\"fnAddProcess('"+posit+"')\"> ";
				unitProcHeader += "<select name=\"userId_^cd\" id=\"userId_^cd\" style=\"width:100px\">";
				unitProcHeader += "	<option value=\"\">-작업자-</option>";
				unitProcHeader += "	^userAll";
				unitProcHeader += "</select> &nbsp; &nbsp; &nbsp;";
				unitProcHeader += "<input type=\"hidden\" name=\"procTypes_^cd\" id=\"procTypes_^cd\" size=\"2\" class=\"inputBox\" value=\""+P_tp+"\"> ";
				unitProcHeader += "<input type=\"hidden\" name=\"rank_^cd\" id=\"rank_^cd\" size=\"3\" class=\"inputBox\" value=\"^rank\"> ";
				unitProcHeader += "<input type=\"hidden\" name=\"flag_^cd\" id=\"flag_^cd\" size=\"1\" class=\"inputBox\" value=\"Y\"> ";
				if (P_tp == "80" ) unitProcHeader += "출하일 : <input type=\"text\" name=\"workDt_^cd\" id=\"workDt_^cd\" size=\"10\" class=\"inputBox\" value=\"^workDt\" style=\"text-align:center\" onclick=\"Calendar_D(this);\"> &nbsp; &nbsp; &nbsp;";
				else unitProcHeader += "작업일 : <input type=\"text\" name=\"workDt_^cd\" id=\"workDt_^cd\" size=\"10\" class=\"inputBox\" value=\"^workDt\" style=\"text-align:center\" onclick=\"Calendar_D(this);\"> &nbsp; &nbsp; &nbsp;";

				var unitProc = "";
				if (P_tp == "10") // 가공
				{
			//alert("DDDDD++++++++++++++++"+P_ex);
					unitProc += "<select name=\"execTime_^cd\" id=\"execTime_^cd\"><option value=\"\">-가공중-</option><option value=\"[주간]\">주간</option><option value=\"[야간]\">야간</option></select> &nbsp; &nbsp; &nbsp;";
					unitProc += "프로그램 No : <input type=\"text\" name=\"working_^cd\" id=\"working_^cd\" value=\"^working\" size=\"10\" class=\"inputBox\" style=\"margin-right:6px\"> &nbsp;";
					unitProc += "사용장비 : <select name=\"etc_^cd\" id=\"etc_^cd\" style=\"width:60px\">^Equips</select> &nbsp; &nbsp; &nbsp;";
					unitProc += "<a title=\"양품/불량\">수량</a> : <input type=\"text\" name=\"goodQty_^cd\" id=\"goodQty_^cd\" style=\"padding:0 0 0 0;width:30px;\" class=\"inputBox\" value=\"^goodQty\" >/<input type=\"text\" name=\"badQty_^cd\" id=\"badQty_^cd\" style=\"padding:0 0 0 0;width:30px;\" class=\"inputBox\" value=\"^badQty\"> <a href=\"javascript:fnAddMemo('^cd_^rank')\"><img src=\"/img/memo_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"메모\"></a> <a href=\"javascript:fnCheckingResult('^rank', 'M')\"><img src=\"/img/test_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"검사\"></a> &nbsp; &nbsp; &nbsp;";
					unitProc += "<span id=\"^cd_^rank\" style=\"padding: 2px 50px 5px 150px;color:#cc3300;display:none;height:25px;\"></span>";
					unitProc = unitProc.split("^Equips").join(G_equip);
					unitProc = unitProc.split("option value=\""+P_etc+"\"").join("option value=\""+P_etc+"\" SELECTED");
				}
				if (P_tp == "20") // 검사
				{
					unitProc += "양품수량 : <input type=\"text\" name=\"goodQty_^cd\" id=\"goodQty_^cd\" size=\"6\" value=\"^goodQty\" class=\"inputBox\" style=\"margin-right:118px\"> &nbsp; &nbsp; &nbsp;";
					unitProc += "불량수량 : <input type=\"text\" name=\"badQty_^cd\" id=\"badQty_^cd\" size=\"6\" value=\"^badQty\" class=\"inputBox\"> <a href=\"javascript:fnAddMemo('^cd_^rank')\"><img src=\"/img/memo_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"메모\"></a> <a href=\"javascript:fnCheckingResult('^rank', 'T')\"><img src=\"/img/test_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"검사\"></a> &nbsp; &nbsp; &nbsp;";
					unitProc += "<span id=\"^cd_^rank\" style=\"padding: 2px 50px 5px 150px;color:#cc3300;display:none;height:25px;\"></span>";
				}
				if (P_tp == "30") // 일반
				{
					unitProc += "작업 : <input type=\"text\" name=\"working_^cd\" id=\"working_^cd\" size=\"30\" class=\"inputBox\" value=\"^working\"> &nbsp; &nbsp; &nbsp;";
					unitProc += "작업시간 : <input type=\"text\" name=\"execTime_^cd\" id=\"execTime_^cd\" size=\"15\" class=\"inputBox\" value=\"^execTime\"> <a href=\"javascript:fnAddMemo('^cd_^rank')\"><img src=\"/img/memo_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"메모\"></a> &nbsp; &nbsp; &nbsp;";
					unitProc += "<span id=\"^cd_^rank\" style=\"padding: 2px 50px 5px 150px;color:#cc3300;display:none;height:25px;\"></span>";
				}
				if (P_tp == "80" ) // 바렐 포장
				{
					unitProc += "수량 : <input type=\"text\" name=\"goodQty_^cd\" id=\"goodQty_^cd\" value=\"^goodQty\" size=\"6\" class=\"inputBox\" style=\"margin-right:143px\"> &nbsp; &nbsp; &nbsp;";
					unitProc += "입고일 : <input type=\"text\" name=\"etc_^cd\" id=\"etc_^cd\" value=\"^etc\" size=\"12\" class=\"inputBox\" style=\"text-align:center\" onclick=\"Calendar_D(this);\"> <a href=\"javascript:fnAddMemo('^cd_^rank')\"><img src=\"/img/memo_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"메모\"></a> &nbsp; &nbsp; &nbsp;";
					unitProc += "<span id=\"^cd_^rank\" style=\"padding: 2px 50px 5px 150px;color:#cc3300;display:none;height:25px;\"></span>";
				}
				if (P_tp == "90") // 포장
				{
					unitProc += "수량 : <input type=\"text\" name=\"goodQty_^cd\" id=\"goodQty_^cd\" value=\"^goodQty\" size=\"6\" class=\"inputBox\" style=\"margin-right:143px\"> &nbsp; &nbsp; &nbsp;";
					unitProc += "포장일 : <input type=\"text\" name=\"etc_^cd\" id=\"etc_^cd\" value=\"^etc\" size=\"12\" class=\"inputBox\" style=\"text-align:center\" onclick=\"Calendar_D(this);\"> <a href=\"javascript:fnAddMemo('^cd_^rank')\"><img src=\"/img/memo_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"메모\"></a> &nbsp; &nbsp; &nbsp;";
					unitProc += "<span id=\"^cd_^rank\" style=\"padding: 2px 50px 5px 150px;color:#cc3300;display:none;height:25px;\"></span>";
				}
				if (P_tp == "98" ) // 출하
				{
					unitProc += "수량 : <input type=\"text\" name=\"goodQty_^cd\" id=\"goodQty_^cd\" value=\"^goodQty\" size=\"6\" class=\"inputBox\" style=\"margin-right:143px\"> &nbsp; &nbsp; &nbsp;";
					unitProc += "출하일 : <input type=\"text\" name=\"etc_^cd\" id=\"etc_^cd\" value=\"^etc\" size=\"12\" class=\"inputBox\" style=\"text-align:center\" onclick=\"Calendar_D(this);\"> <a href=\"javascript:fnAddMemo('^cd_^rank')\"><img src=\"/img/memo_img.gif\" border=\"0\" style=\"margin-top:5px\" alt=\"메모\"></a> &nbsp; &nbsp; &nbsp;";
					unitProc += "<span id=\"^cd_^rank\" style=\"padding: 2px 50px 5px 150px;color:#cc3300;display:none;height:25px;\"></span>";
				}
				unitProc = unitProcHeader + unitProc;
				unitProc = unitProc.split("^processNm").join(posit+". "+P_nm);
				unitProc = unitProc.split("^cd").join(P_cd);
				unitProc = unitProc.split("^userAll").join(G_userAll);
				unitProc = unitProc.split("^working").join(P_wk);
				unitProc = unitProc.split("^execTime").join(P_ex);
				unitProc = unitProc.split("^workDt").join(P_wkDt);
				unitProc = unitProc.split("^goodQty").join(P_goodQty);
				unitProc = unitProc.split("^badQty").join(P_badQty);
				unitProc = unitProc.split("^etc").join(P_etc); 
				unitProc = unitProc.split("^rank").join(P_rank); 
				
				unitProc = unitProc.split("option value=\""+P_uid+"\"").join("option value=\""+P_uid+"\" SELECTED");
				unitProc = unitProc.split("option value=\""+P_ex+"\"").join("option value=\""+P_ex+"\" SELECTED");
				
				var curRank = parseInt(parseInt(P_rank)%100)

				if (curRank > 0)
				{
					var layerCd = "Proc_"+posit+"_"+curRank;
					unitProc = "<span id=\""+layerCd+"\">"+unitProc.replace("<img src=\"http://www.noahtech.kr/img/icon_select.png\" style=\"cursor:hand\" onClick=\"fnAddProcess('"+posit+"')\"> ","")+"<img src=\"/img/bt_orange_del.gif\" style=\"cursor:hand\" onClick=\"fnDelProc('"+layerCd+"','"+posit+"')\"><br></span>";
					
					unitProc = unitProc.replace("frmOrder.workDt_"+P_cd+")","frmOrder.workDt_"+P_cd+"_"+curRank+")");	
					unitProc = unitProc.replace(";position:absolute;","position:absolute;display:none;");	
					unitProc = unitProc.split("_"+P_cd+"\"").join("_"+P_cd+"_"+curRank+"\"");

					$("#layerUnitProc"+posit+"A").css("display","");
					$("#layerUnitProc"+posit+"A").append(unitProc);
				}
				else
				{
					$("#layerUnitProc"+posit).css("display","");
					$("#layerUnitProc"+posit).html(unitProc);
				}
			});


		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});

}

//## 공정 수행 정보 저장
function fnSaveProcess()
{
	if (!$("#fullLotNo").val())
	{
		alert("작업지시 등록후에 저장이 가능합니다");
		return;
	}
	if ($("#lotSubNo").val()=="A")
	{
		alert("연장 작업지시 등록후에 저장이 가능합니다");
		return;
	}
	var divProcCds = $("#processCds").val().split(",");
	var divProcType = $("#procTypes").val().split(",");
	G_saveOrderResult = "";
	// 각각의 공정의 기록을 가져와서 Looping 시키면서 저장한다.
	for (t=1; t<=15; t++)
	{
		if ($("#processCds"+t).val())
		{
			var divProcCds = $("#processCds"+t).val().split(",");
			for (k=0; k<=divProcCds.length; k++)
			{
				var rank = "";
				if (divProcCds[k])
				{
					if (k>0) rank = "_"+k
					var curProcType = $("#procTypes_"+divProcCds[k]+rank).val();
					var param = "processCd="+divProcCds[k];
						param += "&fullLotNo="+$("#fullLotNo").val();
						param += "&lotSubNo="+$("#lotSubNo").val();
						param += "&userId="+$("#userId_"+divProcCds[k]+rank).val();
						param += "&workDt="+$("#workDt_"+divProcCds[k]+rank).val();
						param += "&rank="+$("#rank_"+divProcCds[k]+rank).val();
						param += "&flag="+$("#flag_"+divProcCds[k]+rank).val();
					if (curProcType == "10") // 가공
					{
							param += "&working="+encodeURIComponent($("#working_"+divProcCds[k]+rank).val());
							param += "&etc="+encodeURIComponent($("#etc_"+divProcCds[k]+rank).val());
							param += "&execTime="+encodeURIComponent($("#execTime_"+divProcCds[k]+rank).val());
							param += "&goodQty="+$("#goodQty_"+divProcCds[k]+rank).val();
							param += "&badQty="+$("#badQty_"+divProcCds[k]+rank).val();
					}
					if (curProcType == "20") // 검사
					{
						//alert("attention!! 검사!");
							param += "&goodQty="+$("#goodQty_"+divProcCds[k]+rank).val();
							param += "&badQty="+$("#badQty_"+divProcCds[k]+rank).val();
					}
					if (curProcType == "30") // 일반
					{
							param += "&working="+encodeURIComponent($("#working_"+divProcCds[k]+rank).val());
							param += "&execTime="+encodeURIComponent($("#execTime_"+divProcCds[k]+rank).val());
					}
					if (curProcType == "90" || curProcType == "80" || curProcType == "98") // 포장
					{
							param += "&goodQty="+$("#goodQty_"+divProcCds[k]+rank).val();
							param += "&etc="+encodeURIComponent($("#etc_"+divProcCds[k]+rank).val());
					}
					if ($("#userId_"+divProcCds[k]+rank).val() != undefined)
					{
						if (xMode=="debug") alert(divProcCds[k]+rank+"\r\n"+param);
						if (curProcType != "10") setTimeout("fnSaveOrderResult('"+param+"');",k*100);
					}
					else 
					{
						if (xMode=="debug") alert("-->Error"+divProcCds[k]+rank+"\r\n"+param);					
					}
					if (xMode=="debug") alert("Proc Type : "+curProcType);
					
				}
			}
		}
	}

	if (G_saveOrderResult.indexOf("error!") >-1)
	{
		alert("공정 수행 정보 저장 실패!");
	}
	else
	{
		alert("공정 수행 정보 저장 성공!");
		fnSetJobOrder($("#fullLotNo").val(),$("#lotSubNo").val());
	}

}

var G_saveOrderResult = "";

//## 단위 공정별로 공정 수행 정보 저장
function fnSaveOrderResult(param)
{
	var valUrl = "/action/jobOrder/saveProcDetail.asp";
	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			if ($(xml).find("MSG").text() == "Save OK!")
			{
			}
			else G_saveOrderResult += "error!/";
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

//## 공정 추가
function fnAddProcess(posit)
{
	var curProcCd = $("#"+"processCds"+posit).val();
	var addProcCd = curProcCd.split(",")[0];
	$("#"+"processCds"+posit).val($("#"+"processCds"+posit).val()+","+addProcCd);
	var addProc = $("#layerUnitProc"+posit).html();
	var curRank = curProcCd.split(",").length;
	var layerCd = "Proc_"+posit+"_"+curRank;

	addProcess = "<span id=\""+layerCd+"\">&nbsp; &nbsp; ";
	addProcess += addProc.replace("<IMG style=\"CURSOR: hand\" onclick=\"fnAddProcess('"+posit+"')\" src=\"http://www.noahtech.kr/img/icon_select.png\"> ","");
	addProcess = addProcess.replace(" value=Y "," ")+"<img src=\"/img/bt_orange_del.gif\" style=\"cursor:hand\" onClick=\"fnDelProc('"+layerCd+"','"+posit+"')\"><br></span>";

	addProcess = addProcess.replace("frmOrder.workDt_"+addProcCd+")","frmOrder.workDt_"+addProcCd+"_"+curRank+")");	
	addProcess = addProcess.replace("POSITION: absolute;","POSITION: absolute;display:none;");
	addProcess = addProcess.replace("PADDING-BOTTOM: 5px; PADDING-LEFT: 150px; PADDING-RIGHT: 50px; HEIGHT: 25px; COLOR: #cc3300; PADDING-TOP: 2px","PADDING-BOTTOM: 5px; PADDING-LEFT: 150px; PADDING-RIGHT: 50px; HEIGHT: 25px; COLOR: #cc3300; PADDING-TOP: 2px;display:none")
	addProcess = addProcess.split("_"+addProcCd+" ").join("_"+addProcCd+"_"+curRank+" ");
	
	$("#layerUnitProc"+posit+"A").append(addProcess);
	$("#layerUnitProc"+posit+"A").css("display","");
	if (posit == "1") $("#execTime_"+addProcCd+"_"+curRank).val("");
	$("#userId_"+addProcCd+"_"+curRank).val("");
	$("#badQty_"+addProcCd+"_"+curRank).val("");
	$("#goodQty_"+addProcCd+"_"+curRank).val("");
	$("#workDt_"+addProcCd+"_"+curRank).val(fnGetToday());

}

//function fnTmpDebug(layer)
//{
//	var layerSrc = $("#"+layer).html();
//	alert(layerSrc);
//}

//## 추가한 공정 제거
function fnDelProc(layerCd, posit)
{
	if (confirm("정말로 이공정을 삭제하시겠습니까?"))
	{
		var delProc = $("#"+layerCd).html();
		//alert(delProc);
		delProc = delProc.replace(" value=Y "," value=N ");
		$("#"+layerCd).html(delProc);
		$("#"+layerCd).css("display","none");

		if($("#layerUnitProc"+posit+"A").html().indexOf("SPAN id=Proc") < 0 ) $("#layerUnitProc"+posit+"A").css("display","none");
	}
}

//## 공정 Layer Reset
function fnShowUnitReset()
{
	for(p=1; p<16; p++)
	{
		$("#layerUnitProc"+p).css("display","none");
		$("#layerUnitProc"+p).html("");
		$("#layerUnitProc"+p+"A").css("display","none");
		$("#layerUnitProc"+p+"A").html("");
	}
}

//## 검색 조건 Reset
function fnSearchReset()
{	
	$("#findCompNm").val("");
	$("#findPrdNm").val("");
	$("#findSrcLotNo").val("");
	$("#findType").val("");
	$("#findGoods").val("0");
}

//## 작업 지시 출력
function fnJobOrderPrint(fullLotNo, lotSubNo)
{
	if (lotSubNo=="A" || $("#lotSubNo").val() == "A")
	{
		alert("연장 작업지시 등록후에 저장이 가능합니다");
		return;
	}
	if (!fullLotNo)
	{
		fullLotNo = $("#fullLotNo").val();
		lotSubNo = $("#lotSubNo").val();
	}
	if (!fullLotNo)
	{
		alert("작업지시 등록후에 출력이 가능합니다");
	}
	else window.open("printOrder.asp?fullLotNo="+fullLotNo+"&lotSubNo="+lotSubNo,fullLotNo+"_"+lotSubNo);
}

//## 출하 정보 그리드 표시 ####################

var G_curPage02 = 2;

function grid02List(page)
{	
	var gridNo = 2;
	var xmlNode = "PackList";

	fnResetGrid(gridNo);
	fnNewLoading(gridNo);

	if (!page) page = G_curPage01;
	if (page == undefined) page = 1;
	else G_curPage01 = page;
	var limit = 50;

	var valUrl = "/action/jobOrder/listPackage.asp";
	var Parm = "findCompNm="+encodeURIComponent($("#findCompNm2").val());
		Parm += "&findPrdNm="+encodeURIComponent($("#findPrdNm2").val());
		Parm += "&stDate="+encodeURIComponent($("#stDate").val());
		Parm += "&endDate="+encodeURIComponent($("#endDate").val());
		Parm += "&type="+encodeURIComponent($("#findType2").val());
		Parm += "&findType="+encodeURIComponent($("#findType3").val());
		Parm += "&findLotNo="+encodeURIComponent($("#findLotNo2").val());
		Parm += "&findUserId="+$("#findUserId").val();
		
	if (xMode=="Debug") window.open(valUrl+'?xMode=debug&'+Parm);

	// 그리드 헤더를 기준으로 Cell의 폭을 구해온다.
	var cellWidth = fnGetGridCellWidth(gridNo);	
	// Cell의 정렬방식
	var cellAlign = ",,,left,left,right,,left".split(",");
	// Cell의 링크 걸지 여부 결정
	var cellLink = "N,N,N,N,N,N,N,N,N,".split(",");

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: Parm,
		success: function(xml){
			var gridList = "";
			var k = 1;
			var ttlCnt = $(xml).find(xmlNode).length;
			var startNo = (parseInt(page,10)-1) * limit;
			var endNo = parseInt(page,10) * limit;
			var bgColor = "#FFF";
			var chkCnt = 0;
			
			// 그리드의 부가 정보(레코드수, 페이징) 표시 또는 가리기
			fnGridExtraInfo(gridNo, ttlCnt, page, limit); 

			if (ttlCnt <= endNo) endNo = ttlCnt;
			var no = endNo;
			$(xml).find(xmlNode).each(function(idx){

				if (k>startNo && k<=endNo)
				{
					var company		= $(this).find("company").text();
					var packDt		= $(this).find("packDt").text();
					var lotFullNo	= $(this).find("lotFullNo").text();
					var prdNm		= $(this).find("prdNm").text();
					var goodQty		= $(this).find("goodQty").text();	
					var userNm		= $(this).find("userNm").text();	
					var rank		= $(this).find("rank").text();	
					var billMemo		= $(this).find("billMemo").text();	
											
					var showLotNo = "&nbsp;"+lotFullNo.replace("-0","");
									
					var arrVal = new Array();
					var vNo = parseInt(no,10)-1;
					if (company == "<b>합 계</b>") arrVal[0] = "&nbsp;";
					else arrVal[0] = "<p><input type='checkbox' name='bizBill' id='bizBill' onClick='fnAddBill(this)' value='"+lotFullNo+"^"+rank+"'> "+vNo+"</p>";
					arrVal[1] = "<p>"+company+"</p>";
					arrVal[2] = "<p>"+packDt+"</p>";
					arrVal[3] = "<p>"+showLotNo+"</p>";
					arrVal[4] = "<p>"+prdNm+"</p>";
					arrVal[5] = "<p>"+goodQty+"</p>";
					arrVal[6] = "<p>"+userNm+"</p>";
					arrVal[7] = "<p>&nbsp;"+billMemo;+"</p>";
										
					var link = "";

					//gridList = fnDrawCell(lotYear, lotNo, lotSubNo, processCd);
					gridList = fnDrawCell(arrVal, bgColor, cellWidth, cellAlign, '', link, cellLink);

					$("#"+"gridBody"+gridNo).append(gridList);
				}
				no = parseInt(endNo,10)-parseInt(k,10);
				k++;			
			});			
		},
		error: function(xml){
			alert('Error!!\r\n'+xml.responseText);
		}
	});
}

//## 거래명세서 추가하기
function fnAddBill(obj)
{
	var orgValue = $("#bizBillInfo").val();
	if (obj.checked == true)
	{
		$("#bizBillInfo").val(orgValue+obj.value+",");
	}
	else
	{
		orgValue = orgValue.replace(obj.value+",","");
		$("#bizBillInfo").val(orgValue);
	}
}

//## 거래명세서 메모 레이어 열기

//## 공정 메모 열기
function fnOpenBizBillMemo()
{
	$("#income").val("");
	$("#billMemo").val("");
	$("#bizBillMemo").css("top",97);
	$("#bizBillMemo").css("left",163);
	$("#bizBillMemo").css("display","");
	$("#income").focus();
}

//## 거래 명세서 만들기
function fnMkBizBill()
{
	if ($("#findType2").val()!='98')
	{
		alert("출하에서만 거래명세서를 발행할 수 있습니다.");
		return;
	}
	if (confirm("거래명세서를 발행하시겠습니까?"))
	{		
		if (!$("#income").val())
		{
			alert("내역을 바르게 입력해 주세요");
			$("#income").focus();
			return;
		}
		if (!$("#bizBillInfo").val())
		{
			alert("거래명세서 발행할 항목을 선택해 주세요");
			return;
		}
		var valUrl  = '/action/jobOrder/saveBizBill.asp';
		var param  = "bizBillInfo="+$("#bizBillInfo").val();
			param += "&income="+encodeURIComponent($("#income").val());
			param += "&billMemo="+encodeURIComponent($("#billMemo").val());
			param += "&flag=Y";
		
		if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);
	
		$.ajax({
			url: valUrl,
			type: 'POST',
			dataType: 'xml',
			data: param,
			success: function(xml){
				fnSessionCheck($(xml).find("MSG").text());
				if ($(xml).find("MSG").text() == "Save OK!")
				{
					alert("거래명세서 발급 OK!");
					$("#bizBillInfo").val("");
					$("#income").val("");
					$("#billMemo").val("");
					fnLayerClose('bizBillMemo');
					grid02List();
				}
				else alert($(xml).find("MSG").text());
			},
			error: function(xml){
				alert('Error!!');
				alert(xml.responseText);
			}
		});
	}
}

//## 출하정보 조건 Reset
function fnSearch2Reset()
{
	$("#findCompNm2").val("");
	$("#findPrdNm2").val("");
	$("#findType").val("98");
}

//## 제품 정보 가져오기
function setPrdInfo(prdCd)
{
	var valUrl = "/action/product/view.asp";
	var param = "prdCd="+prdCd;

	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());
			
			$("#sourceSize").val($(xml).find("sourceSize").text());
			
			fnFindCompany('',$(xml).find("compCd").text(),'compCd');			

		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}